package com.kzy.demoadmin.web.mapper;


import com.kzy.demoadmin.web.entity.Book;
import com.kzy.demoadmin.web.entity.BookPageQuery;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {
    /**
     * 根据id查询书籍
     * @param integer
     * @return
     */
    @Select("select * from book where id = #{id}")
    Book findById(@Param("id") Integer integer);//@Param是

    /**
     * 分页查询
     * @param query
     * @return
     */
    List<Book> searchBy(BookPageQuery query);

    /**
     * 删除书籍
     * @param id
     * @return
     */
    @Delete("delete from book where id = #{id}")
    int deleteById(Integer id);

    /**
     * 新增书籍
     * @param book
     */
    void insert(Book book);

    /**
     * 修改书籍
     * @param book
     */
    void update(Book book);

    /**
     * 查询所有书籍
     * @return
     */
    @Select("select book.*,book_type.name as typeName from book left join book_type on book.book_type = book_type.id")
    List<Book> getAll();
}
